package daniel.almaguer.test;


import android.app.Activity;
import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;




public class ImageAdapterActivity extends Activity {
	
	private String message = "";
	
	   @Override
	   
	   /*
	    @author 	Daniel Almaguer, Cesar Castro	
	    @param 	Se define el metodo onCreate()
	    @return 	Debuggeo image adapter.
	    @see 	
	    @throws 	No Exception
	    @version    2.0
	    */
	   
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState); 
	        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	        
	        message = getIntent().getExtras().getString("passed");
	        message = message.trim();
	        String []lugares = new String[6];
	        lugares = message.split(" ");
	   
	        System.out.println("Entro a ImageAdapterActivity: " + message);
	        System.out.println("Lugares en [4] = " +lugares[4]);
	        setContentView(R.layout.adapter);
	        
	        GridView gridView;
			gridView = (GridView) findViewById(R.id.gridView1);
			gridView.setAdapter(new ImageAdapter(this, lugares));
			gridView.setOnItemClickListener(new OnItemClickListener() {
				
				 /*
			    @author 	Daniel Almaguer, Cesar Castro	
			    @param 	Se define el metodo onItemClick()
			    @return 	Manejo de las selecciones del usuario en los botones de opciones de cada monumento.
			    @see 	
			    @throws 	No Exception
			    @version    2.0
			    */
				
				public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
					
						Toast.makeText(
							   getApplicationContext(),
							   ((TextView) v.findViewById(R.id.grid_item_label))
							   .getText(), Toast.LENGTH_SHORT).show();
						
						
						//////Testing
		                //set up dialog
		                Dialog dialog = new Dialog(ImageAdapterActivity.this);
		                dialog.setContentView(R.layout.max_info);
		                dialog.setTitle(((TextView) v.findViewById(R.id.grid_item_label))
								   .getText());
		                dialog.setCancelable(true);
		 
		                //set up text
		                TextView text = (TextView) dialog.findViewById(R.id.TextView01);
		                
		                if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("pisa"))
		                	text.setText(R.string.string_pisa);
		                else if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("iglesia"))
		                	text.setText(R.string.string_iglesia);
		                else if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("eiffel"))
		                	text.setText(R.string.string_eiffel);
		                else if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("liberty"))
		                	text.setText(R.string.string_liberty);
		                else if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("arco"))
		                	text.setText(R.string.string_arco);
		                else if(((TextView) v.findViewById(R.id.grid_item_label)).getText().equals("cRede"))
		                	text.setText(R.string.string_cRede);
		 
		                //set up image view
		               // ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
		               // img.setImageResource(R.drawable.image);
		 
		                //set up button
		                Button button = (Button) dialog.findViewById(R.id.Button01);
		                button.setOnClickListener(new OnClickListener() {
		                    public void onClick(View v) {
		                        finish();
		                    }
		                });
		                //now that the dialog is set up, it's time to show it    
		                dialog.show();
						
						/////Finaliza TEsting
						}
					});
	   }
}